const Router = require('koa-router')
const router = new Router({ prefix: '/kcss' })

// 考场设施
const facilities = [{
  id: 1,
  title: '考试场地',
  src: '/imgs/facilities1.png'
}, {
  id: 2,
  title: 'C1-C2车型',
  src: '/imgs/facilities2.png'
}, {
  id: 3,
  title: 'B2车型',
  src: '/imgs/facilities3.png'
}, {
  id: 4,
  title: 'B1-A1-A3车型（校车接送）',
  src: '/imgs/facilities4.png'
}, {
  id: 5,
  title: '模拟教室',
  src: '/imgs/facilities5.png'
}, {
  id: 6,
  title: '科目一理论考试',
  src: '/imgs/facilities6.png'
}]

router.get('/', async (ctx) => {
  ctx.response.status = 200
  ctx.config.nav[2].checked = true
  ctx.config.title = '考场设施_走进八益_达州八益驾校'
  ctx.config.description = '考场设施'
  ctx.config.keyword = '考场设施'

  await ctx.render('kcss.ejs', {
    config: ctx.config,
    facilities
  })
})

router.get('/:id\.html', async (ctx) => {
  ctx.response.status = 200
  const id = ctx.params.id || ''
  ctx.config.nav[2].checked = true
  ctx.config.title = '考场设施详情'
  ctx.config.description = '考场设施详情'
  ctx.config.keyword = '考场设施详情'
  let i = 0
  facilities.forEach((item, index) => {
    if (id == item.id) {
      ctx.config.title = item.title
      ctx.config.description = item.title
      ctx.config.keyword = item.title
      i = index
    }
  })

  const infoData = {
    prev: i < 1 ? null : facilities[i - 1],
    current: facilities[i],
    next: i >= facilities.length - 1 ? null : facilities[i + 1]
  }
  
  await ctx.render('kcssxq.ejs', {
    config: ctx.config,
    infoData
  })
})

module.exports = router